//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XImage.h>
///	@path	~/src/gui/xgui/
///	@date	2008/10/30
///	@brief	.

#pragma once

#include "xeres.h"

#include "gui/IGuiControl.h"
#include "gui/style/style.h"
#include "gui/image/IBitmap.h"

namespace xeres {

	/*! 
		\class	XImage
		\brief	Presents an image to display.
	*/
	class XImage : public IGuiControl
	{
	public:

		/// \ctor
		XImage( void );

		/// \ctor
		XImage( RefWeak<IBitmap> resource , const Rect<int>& placement );

		/// \dtor
		virtual ~XImage( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XImage , IGuiControl );

	public:

		/// \name Button Methods
		//@{

		/// \brief	Set parent component.
		virtual bool SetParent( RefWeak<IGuiForm> parent );

		/// \brief	Can have focus.
		virtual bool CanHaveFocus( void ) const { return false; }

		/// \brief	Set image resource.
		void SetImage( RefWeak<IBitmap> resource );

		/// \brief	Get image resource.
		RefWeak<IBitmap> GetImage( void ) const { return m_image; }

		/// \brief	Get image style.
		RefWeak<CImageStyle> GetStyle( void );

		/// \brief	Rewind image.
		void Rewind( void );

		/// \brief	Set transparency.
		void SetTransparency( float trans );

		/// \brief	Get transparency.
		float GetTransparency( void ) { return m_transparency; }

		//@}

		/// \name Presentation Manipulation
		//@{

		/// \brief	Tick update.
		virtual void Tick( Updater& updater , float dTime );

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( Composition& composition );

		//@}

	private:

		//@ data
		Ref<IBitmap>		m_image;
		Ref<CImageStyle>	m_style;
		float				m_transparency;
		float				m_time;
		int					m_frame;
	};

	/*! 
		\class	XAnimation
		\brief	Presents an animation to display.
	*/
	class XAnimation : public IGuiControl
	{
	public:

		/// \ctor
		XAnimation( void );

		/// \ctor
		XAnimation( RefWeak<IBitmap> resource , const Rect<int>& placement );

		/// \dtor
		virtual ~XAnimation( void );

		DECL_IOBJECT_CLASS_DYNAMIC( XAnimation , IGuiControl );

	public:

		/// \name Animation Methods
		//@{

		/// \brief	Set parent component.
		virtual bool SetParent( RefWeak<IGuiForm> parent );

		/// \brief	Can have focus.
		virtual bool CanHaveFocus( void ) const { return false; }

		/// \brief	Set animation resource (will reset play to 0).
		void SetImage( RefWeak<IBitmap> resource );

		/// \brief	Get animation resource.
		RefWeak<IBitmap> GetImage( void ) const { return m_ani; }

		/// \brief	Set image style.
		RefWeak<CImageStyle> GetStyle( void );

		/// \brief	Set transparency.
		void SetTransparency( float trans );

		/// \brief	Get transparency.
		float GetTransparency( void ) { return m_transparency; }

		/// \brief	Set speed.
		void SetSpeed( float speedFps );

		/// \brief	Get speed.
		float GetSpeed( void ) const { return m_speed; }

		/// \brief	Set play count (-1 means play loop forever).
		void SetPlayCount( int play );

		/// \brief	Get rest play times.
		int GetPlayCount( void ) const { return m_rest; }

		/// \brief	Is animation stopped.
		bool IsStopped( void ) const { return m_rest == 0; }

		//@}

		/// \name Presentation Manipulation
		//@{

		/// \brief	Tick update.
		virtual void Tick( Updater& updater , float dTime );

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( Composition& composition );

		//@}

	private:

		//@ data
		Ref<IBitmap>		m_ani;
		Ref<CImageStyle>	m_style;
		float				m_play;
		float				m_transparency;
		float				m_speed;
		int					m_rest;
	};


} // namespace xeres
